﻿package com.plter.controls.asmax
{
	import flash.display.GradientType;
	import flash.display.SpreadMethod;
	import flash.geom.Matrix;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	
	/**
	 * ...
	 * @author Jaja as-max.cn
	 */
	internal final class ATitleBar extends ASprite
	{
		private var txt:TextField = new TextField;
		private var mat:Matrix = new Matrix;
		
		public function ATitleBar() :void
		{
			//init mat 
			mat.createGradientBox(10, 10, Math.PI / 2);
			
			drawBG(316, 20, 0xCCCCCC, 0xFAFAFA);
			
			txt.autoSize = TextFieldAutoSize.LEFT;
			txt.selectable = false;
			txt.mouseEnabled = false;
			txt.x = 2;
			txt.text = "AForm";
			addChild(txt);
		}
		
		/**
		 * 绘制背景
		 * @param	wid				背景宽度
		 * @param	hei				背景高度
		 * @param	fillColor		填充颜色
		 * @param	lineColor		边框颜色
		 * @param	ellipseWidth	圆角宽度
		 * @param	ellipseHeight	圆角高度
		 */
		public override function drawBG(wid:Number = 320, hei:Number = 240, fillColor:uint = 0xEEEEEE, lineColor:uint = 0xCCCCCC, ellipseWidth:int = 15, ellipseHeight:int = 15):void 
		{
			bgWidth = wid;
			bgHeight = hei;
			bgFillColor = fillColor;
			bgLineColor = lineColor;
			bgEllipseWidth = ellipseWidth;
			bgEllipseHeight = ellipseHeight;
			
			bgShape.graphics.clear();
			bgShape.graphics.beginGradientFill(GradientType.LINEAR, [0xFFFFFF, fillColor], [1, 1], [0x00, 0xFF], mat, SpreadMethod.PAD);
			bgShape.graphics.lineStyle(1.5, lineColor);
			bgShape.graphics.drawRoundRect(0, 0, wid, hei, ellipseWidth, ellipseHeight);
			bgShape.graphics.endFill();
		}
		
		/**
		 * 设置窗体标题
		 */
		public function set title(value:String):void {
			txt.text = value;
		}
		/**
		 * 获得窗体标题
		 */
		public function get title():String {
			return txt.text;
		}
		
	}
	
}

